/* eslint-disable no-unused-vars */
import React, { useEffect, useState } from 'react';
import { useParams, useHistory } from 'react-router-dom';
import { search } from '../../api/actions/article';
import ArticleList from '../../components/ArticleList';

const Search = () => {
  const { text } = useParams();
  const [posts, setPosts] = useState([]);
  useEffect(() => {
    if (text) {
      const fetchData = async () => {
        const res = await search({
          text,
        });
        if (res.code === 0) {
          setPosts(res.data || []);
        }
      };
      fetchData();
    }
  }, [text]);
  return (
    <ArticleList posts={posts} />
  );
};

export default Search;
